Ext.define("app.system.account.form", {
	extend : 'Ext.window.Window',
	title : '编辑账号信息',
	height : 600,
	width : 800,
	closable : true,
	resizable : false,
	modal : true,
	constrain : true,
	plain : true,
	layout : {
		type : 'border'
	},
	requires : [ 'app.system.role.field' ],
	initComponent : function() {
		var me = this;
		me.form = me.createForm();
		Ext.apply(me, {
			items : [ me.form ],
			buttons : [ {
				text : '确认',
				bodyStyle : 'padding:0 0 0 5px',
				handler : function() {
					me.submitForm();
				}
			}, {
				text : '关闭',
				bodyStyle : 'padding:0 0 0 5px',
				handler : function() {
					me.close();
				}
			} ]
		});
		me.callParent(arguments);
	},
	submitForm : function() {
		var me = this;
		var params = {};
		evt.submit(me.form, systemUrl + '/boyon/account/create', params,
				function() {
					Ext.Msg.alert('提示', '操作成功');
					me.parentTarget.reloadStore();
					me.close();
				});
	},
	loadData : function(form) {

	},
	createForm : function() {
		var me = this;
		var fields = me.createField();
		var form = Ext.create('Ext.form.Panel', {
			layout : 'column',
			region : 'center',
			items : fields,
			listeners : {
				afterrender : function() {
					me.loadData(form);
				}
			}
		});
		return form;
	},
	createField : function() {
		var me = this;
		var array = new Array();
		utils.pushfieldarray(array, '1', {
			name : 'account',
			beforeLabelTextTpl : required,
			fieldLabel : '账号',
			allowBlank : false,
			columnWidth : .5,
			minLength : 1,
			maxLength : 16
		});
		utils.pushfieldarray(array, 'app.widget.value', {
			name : 'accountType',
			beforeLabelTextTpl : required,
			fieldLabel : '账号类型',
			valueField : 'value',
			displayField : 'displayName',
			valueType : 0,
			columnWidth : .5,
			parentTarget : me,
			func : me.handlerAccountType,
			editable : false,
			allowBlank : false
		});
		utils.pushfieldarray(array, '4', {
			name : 'roleId'
		});
		utils.pushfieldarray(array, 'app.system.role.field', {
			name : 'roleName',
			beforeLabelTextTpl : required,
			fieldLabel : '角色',
			allowBlank : false,
			parentTarget : me,
			columnWidth : 1
		});
		return array;
	},
	handlerAccountType : function(array) {
		var accountType = utils.getAccountField('accountType');
		var newArray = new Array();
		for (var i = 0; i < array.length; i++) {
			var obj = array[i];
			if (accountType == 0) {
				if (obj.value == 1) {
					newArray.push(obj);
				}
			} else if (accountType == 1) {
				if (obj.value == 2) {
					newArray.push(obj);
				}
			}
		}
		return newArray;
	},
	callBackRole : function(rec) {
		var me = this;
		me.form.getForm().findField('roleId').setValue(rec.get('roleId'));
		me.form.getForm().findField('roleName').setValue(rec.get('roleName'));
	}
});